//
//  YXSettingViewController.m
//  MockProject
//
//  Created by FanYu on 8/20/16.
//  Copyright © 2016 niuzhaowang. All rights reserved.
//

#import "YXSettingViewController.h"
#import "YXHomeTableViewCell.h"
#import "YXGeneralViewController.h"
#import "YXAboutViewController.h"

@interface YXSettingViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) YXGeneralViewController *generalVC;
@property (nonatomic, strong) YXAboutViewController *aboutVC;

@end

@implementation YXSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置";
    
    [self setupUI];
    [self configData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - SetupUI 
- (void)setupUI {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor colorWithHexString:@"f5f5f5"];
    self.tableView.rowHeight = 50;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
    self.tableView.separatorColor = [UIColor colorWithHexString:@"e0dcd9"];
    [self.tableView registerNib:[UINib nibWithNibName:@"YXHomeTableViewCell" bundle:nil] forCellReuseIdentifier:@"YXHomeTableViewCell"];
    [self.view addSubview:self.tableView];
}


#pragma mark - Helper
- (void)configData {
    YXSettingCellModel *model1 = [YXSettingCellModel configWithTitle:@"通用设置" icon:@"通用设置icon" number:@"" isOn:NO];
    YXSettingCellModel *model2 = [YXSettingCellModel configWithTitle:@"关于我们" icon:@"关于我们icon" number:@"'" isOn:NO];
    self.dataArray = @[model1, model2];
}

- (void)pushGeneralViewController {
    self.generalVC = [[YXGeneralViewController alloc] init];
    [self.navigationController pushViewController:self.generalVC animated:YES];
}

- (void)pushAboutViewController {
    self.aboutVC = [[YXAboutViewController alloc] init];
    [self.navigationController pushViewController:self.aboutVC animated:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YXHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YXHomeTableViewCell" forIndexPath:indexPath];
    
    cell.cellModel = self.dataArray[indexPath.row];
    
    return cell;
}


#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        [self pushGeneralViewController];
    } else {
        [self pushAboutViewController];
    }
}



@end
